package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.esm.model.User;
import com.esm.service.UserService;
import com.esm.serviceimpl.UserServiceImpl;
import com.esm.utils.PrintWriterUtil;

import net.sf.json.JSONObject;

/**
 * AddEmployeeController
 * 新增员工控制者
 * @author 魏长均
 *
 */
public class AddEmployeeController_wcj extends HttpServlet
{
	private static final long serialVersionUID = 1L;
	UserService uService = new UserServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	{
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	{
		String uname = req.getParameter("uname");
		String upsw = req.getParameter("upsw");
		String usex = req.getParameter("usex");
		String uage = req.getParameter("uage");
		String uidcard = req.getParameter("uidcard");
		String utelphone = req.getParameter("utelphone");
		int dep_id = Integer.parseInt(req.getParameter("dep_id"));
		int sal_id = Integer.parseInt(req.getParameter("sal_id"));
		int rid = Integer.parseInt(req.getParameter("rid"));
		User addEmployee = new User(uname,upsw,usex,uage,uidcard,utelphone,dep_id,sal_id,rid);
		boolean flag = uService.addEmployee(addEmployee);
		PrintWriter pw = resp.getWriter();
		JSONObject jo = new JSONObject();
		jo.put("flag", flag);
		PrintWriterUtil.flushJoAndClosePrintWriter(pw, jo);
	}
}
